package com.cykj.pos.applet.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cykj.common.annotation.DataSource;
import com.cykj.common.config.RuoYiConfig;
import com.cykj.common.constant.Constants;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.DataSourceType;
import com.cykj.common.utils.StringUtils;
import com.cykj.pos.applet.domain.ao.AppletAO;
import com.cykj.pos.applet.domain.ao.SignAO;
import com.cykj.pos.applet.domain.vo.TransactionsVO;
import com.cykj.pos.applet.mapper.AppletMapper;
import com.cykj.pos.applet.domain.Applet;
import com.cykj.pos.applet.service.AppletService;
import com.cykj.pos.domain.BizVerifyCode;
import com.cykj.pos.domain.dto.VerifyCodeDTO;
import com.cykj.pos.enums.bizstatus.BizStatusContantEnum;
import com.cykj.pos.service.ISMSService;
import com.cykj.pos.service.impl.BizVerifyCodeServiceImpl;
import com.cykj.pos.util.DateUtils;
import com.cykj.pos.util.VerifyCodeUtils;
import com.github.qcloudsms.SmsSingleSenderResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author wangjiaqi
 * @date 2022/1/24
 */
@Service
@Slf4j
public class AppletServiceImpl extends ServiceImpl<AppletMapper, Applet> implements AppletService {

    @Resource(name = "appletMapper")
    private AppletMapper appletMapper;

    @Autowired
    private BizVerifyCodeServiceImpl bizVerifyCodeServiceImpl;

    @Override
    public AjaxResult sign(SignAO signAO) {
        //验证 验证码
        BizStatusContantEnum bizStatus = bizVerifyCodeServiceImpl.verifyCodeValidate(signAO.getPhone(),
                signAO.getCode());
        if (bizStatus != BizStatusContantEnum.SMS_SUCCESS) {
            return AjaxResult.error("短信验证码校验失败");
        }
        //手机号在商户报件表存在不
        String phoneExit = appletMapper.getPhone(signAO.getPhone());
        if (StringUtils.isNotEmpty(phoneExit)) {
            return AjaxResult.success("登录成功");
        }
        return AjaxResult.error("该手机号暂无报件信息");
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<TransactionsVO> getList(AppletAO appletAO) {
        return appletMapper.getSnCodeList(appletAO);
    }

}
